﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using BLL;
using Model;
namespace UI
{
    public partial class 顾客开单 : Form
    {
        private TabPage tp;
        private 主界面 主界面;
        private string p;

        public 顾客开单()
        {
            InitializeComponent();
        }

        public 顾客开单(TabPage tp, UI.主界面 主界面, string p)
        {
            // TODO: Complete member initialization
            this.tp = tp;
            this.主界面 = 主界面;
            this.p = p;
            InitializeComponent();
        }
        string TableID;
        private void 顾客开单_Load(object sender, EventArgs e)
        {
            ModelRoomType mr = (ModelRoomType)tp.Tag;
            ListView li = (ListView)tp.Controls[0];
            DataRow dr = (DataRow)li.SelectedItems[0].Tag;
            TableID = dr["TableID"].ToString();
            label1.Text = dr["TableName"].ToString();
            label2.Text = mr.RTName;
            label3.Text = mr.RTConsume+"";
        }

        private void button2_Click(object sender, EventArgs e)
        {
           
            
            this.Close();
            
        }


        public void dk(Model_ConsumerBill m){
          ListView li = (ListView)tp.Controls[0];
                           
                            DataRow dr = (DataRow)li.SelectedItems[0].Tag;
                            // MessageBox.Show(dr["TableID"].ToString());
                            //修改餐桌状态
                            BLL_Tables.UP_ZhuoZi_ZT(dr["TableID"].ToString());
                            
                            主界面.FJ();          

    }
        private void button1_Click(object sender, EventArgs e)
        {

           
                if (textBox1.Text.Length > 0)
                {
                    if (int.Parse(textBox1.Text)>0)
                    {
                   
                    
                    //判断有没有输入会员号
                    if (textBox2.Text.Trim() == "")
                    {

                        Model_ConsumerBill m = new Model_ConsumerBill();
                        m.CBID = "ZD" + DateTime.Now.Year + DateTime.Now.Month + DateTime.Now.Day + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second;
                        m.TableID = TableID;
                        m.CBAmount = textBox1.Text;
                        m.VipID =null;
                        m.CBDiscount = "1";
                        m.AdminID = p;
                        BLL_ConsumerBill.TJxf(m);
                        dk(m);
                        if (checkBox1.Checked == true)
                        {
                            添加消费 t = new 添加消费(tp, 主界面, m);
                            t.ShowDialog();
                            this.Close();
                        }
                        
                    }
                    else
                    {
                        //获取会员等级
                        object JG = BLL_Vips.PD_SF_HY(textBox2.Text);
                        if (JG == null)
                        {
                            MessageBox.Show("会员号有误");
                        }
                        else
                        {
                            
                            Model_ConsumerBill m = new Model_ConsumerBill();
                            m.CBID = "ZD" + DateTime.Now.Year + DateTime.Now.Month + DateTime.Now.Day + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second;
                           // MessageBox.Show(m.CBID);
                            m.TableID = TableID;
                            m.CBAmount = textBox1.Text;
                            m.VipID = textBox2.Text;
                            //用会员等级获取折扣
                            m.CBDiscount =BLL_Vips.HYDJ(JG.ToString()).ToString();
                            m.AdminID = p;
                            BLL_ConsumerBill.TJxf(m);
                            dk(m);
                            if (checkBox1.Checked == true)
                            {
                                添加消费 t = new 添加消费(tp, 主界面, m);
                                t.ShowDialog();
                                this.Close();
                            }
                        }
                    }
                    }
                    else
                    {
                        MessageBox.Show("顾客人数不能少于零");
                    }  
                }
                else
                {
                    MessageBox.Show("请输入顾客人数");
                }
           
          
           
        }

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (char.IsNumber(e.KeyChar) || e.KeyChar==8)
            {
                
            }
            else
            {
                e.Handled = true;
            }
        }
    }
}
